package com.bao123.utils.encryption;

import sun.misc.BASE64Encoder;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * md5加密类
 * @author lbw
 */
public class Md5Util {
    public static final String USER_PASSWORD_USE = "lbwPasswordUse";
    public static final String EMPTY_SALT = "";

    public static String encoderByMd5(String str, String salt) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        BASE64Encoder base64 = new BASE64Encoder();
        str += salt;
        return base64.encode(md5.digest(str.getBytes(StandardCharsets.UTF_8)));
    }

}
